package sma.iss;


import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sma.iss.file.CsvIss;
import sma.nasa.ISSVis;

public class RenderCsvRun {

	/** Logger for this class. */
	private final static Logger LOGGER = LoggerFactory.getLogger(RenderCsvRun.class);
	
	/** -rendering parameter. */
	private final static boolean RENDERING = false;

	/** All values of beta to be tested. */
	private final static double[] ALL_BETA = new double[] { 70, -72, 72, 74, -70, -74 };

	/** All values of beta for system tests. */
	private final static double[] ALL_SYSTEM_BETA = new double[] { 71, 73, 75, -71, -73, -75 };

	private static final double DEFAULT_YAW = 0.0;

	@Test
	public void runBetaGen() throws IOException {
		LOGGER.info("runBetaGen");
		this.testInternal(-71);
	}

	@Test
	public void runBeta74() throws IOException {
		LOGGER.info("testBeta74");
		this.testInternal(74);
	}

	@Test
	public void runBeta72() throws IOException {
		LOGGER.info("runBeta72");
		this.testInternal(72);

	}

	@Test
	public void runBetaM74() throws IOException {
		LOGGER.info("testBetaM74");
		this.testInternal(-74);

	}

	@Test
	public void runBeta70() throws IOException {
		LOGGER.info("runBeta70");
		this.testInternal(70);

	}

	@Test
	public void runBetaM70() throws IOException {
		LOGGER.info("runBeta -70");
		this.testInternal(-70);
	}

	@Test
	public void runBetaM72() throws IOException {
		this.testInternal(-72);
	}

	// @Test
	public void testAllBeta() throws IOException {
		this.testBetaArray(ALL_BETA);
	}

	@Test
	public void testAllSystemBeta() throws IOException {
		this.testBetaArray(ALL_SYSTEM_BETA);
	}

	private void testBetaArray(double[] betaArray) throws IOException {
		for (int i = 0; i < betaArray.length; i++) {
			double betaToTest = betaArray[i];
			LOGGER.info("testBetaArray, beta={}, remaining {}", betaToTest, ALL_BETA.length - i);
			this.testInternal(betaToTest);
		}
	}

	private void testInternal(double beta) throws IOException {
		// the object to test
		double yaw = DEFAULT_YAW;
		LOGGER.info("beta={}", beta);

		String csvFileName = CsvIss.getCsvTryName(beta, yaw);
		
	
		List<String> lstParams = new ArrayList<String>();
		String[] arg = new String[] { "-beta", Double.toString(beta), "-csv", csvFileName };
		lstParams.addAll(Arrays.asList(arg));

		if (RENDERING) {
			lstParams.add("-rendering");
		}
		ISSVis.main(lstParams.toArray(new String[] {}));
		LOGGER.info("end");
	}

}
